package com.sc.consumber_feign.controller;


import com.sc.consumber_feign.entity.Goods;
import com.sc.consumber_feign.service.RemoteFeignService;
import com.sc.consumber_feign.vo.ActionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class GoodsController {

    @Autowired(required = false)
    private RemoteFeignService remoteFeignService;


    @RequestMapping(value = "/goodss",method = RequestMethod.GET)
    public ActionResult findGoods()
    {
        List<Goods> goods=remoteFeignService.findGoods();
        ActionResult actionResult=new ActionResult(200,"find all success",goods);
        return  actionResult;
    }


    @RequestMapping(value = "/goods/{id}",method = RequestMethod.GET)
    public ActionResult findOneGoods(@PathVariable(value = "id") int id)
    {
        Goods onegoods=remoteFeignService.findOneGoods(id);
        ActionResult actionResult=new ActionResult(200,"find ond success",onegoods);
        return  actionResult;
    }

    @RequestMapping(value = "/addGoods",method = RequestMethod.POST)
    public ActionResult addGoods(@RequestBody Goods goods)
    {
        Goods onegoods=remoteFeignService.addGoods(goods);
        ActionResult actionResult=new ActionResult(200,"add goods success",onegoods);
        return  actionResult;
    }

    @RequestMapping(value = "/updateGoods",method = RequestMethod.PUT)
    public ActionResult updateGoods(@RequestBody Goods goods)
    {
        Goods onegoods=remoteFeignService.updateGoods(goods);
        ActionResult actionResult=new ActionResult(200,"update  goods success",onegoods);
        return  actionResult;
    }

    @RequestMapping(value = "/deleteGoods/{id}",method = RequestMethod.DELETE)
    public ActionResult deleteGoods(@PathVariable(value = "id") int id)
    {
        Boolean aBoolean=remoteFeignService.deleteGoods(id);
        ActionResult actionResult=new ActionResult(200,"delete  goods success",aBoolean);
        return  actionResult;
    }
}
